import { defineStore } from 'pinia'
export const useMenuStore = defineStore('menu', {
  state: () => ({
    menus: [
      {
        type: 'slider',
        name: '首页统计',
        icon: 'Histogram',
        index: '/home/index',
        active: true,
        type: '',
        children: [
        ]
      },
      {
        type: 'slider',
        name: '员工管理',
        icon: 'Document',
        index: 'person',
        active: false,
        children: [
          {
            type: 'slider',
            name: '员工列表',
            icon: 'Document',
            index: '/home/person',
            active: true,
            children: []
          }
        ]
      },
      {
        type: 'slider',
        name: '客服管理',
        icon: 'Management',
        index: 'customer',
        active: true,
        children: [
          {
            type: 'slider',
            name: '客服列表',
            icon: 'Management',
            index: '/home/customer',
            active: true,
            children: []
          }
        ]
      },
      {
        type: 'slider',
        name: '商品',
        icon: 'Management',
        index: 'books',
        active: false,
        children: [
          {
            type: 'slider',
            name: '基础',
            icon: 'Management',
            index: '/home/books',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '普通书籍',
            icon: 'Management',
            index: '/home/putong',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '精品书籍',
            icon: 'Management',
            index: '/home/jingpin',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '新品书籍',
            icon: 'Document',
            index: '/home/newBooks',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '黑名单',
            icon: 'Document',
            index: '/home/blackBooks',
            active: true,
            children: []
          }
        ]
      },
      {
        type: 'slider',
        name: '订单管理',
        icon: 'Management',
        index: 'order',
        active: true,
        children: [
          {
            type: 'slider',
            name: '订单列表',
            icon: 'Management',
            index: '/home/order',
            active: true,
            children: []
          }
        ]
      },
      {
        type: 'slider',
        name: '金钱管理',
        icon: 'Management',
        index: 'tixian',
        active: true,
        children: [
          {
            type: 'slider',
            name: '提现列表',
            icon: 'Management',
            index: '/home/tixian',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '余额列表',
            icon: 'Management',
            index: '/home/yue',
            active: true,
            children: []
          }
        ]
      },
      {
        type: 'slider',
        name: '会员管理',
        icon: 'Management',
        index: 'huiyuan',
        active: true,
        children: [
          {
            type: 'slider',
            name: '会员列表',
            icon: 'Management',
            index: '/home/huiyuan',
            active: true,
            children: []
          }
        ]
      },
      {
        type: 'slider',
        name: '设置',
        icon: 'Management',
        index: 'config',
        active: false,
        children: [
          {
            type: 'slider',
            name: '书籍类型',
            icon: 'Management',
            index: '/home/bookTypes',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '回收书籍规则',
            icon: 'Management',
            index: '/home/getConfig',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '仓库列表',
            icon: 'Management',
            index: '/home/cangku',
            active: true,
            children: []
          },
          // {
          //   type: 'slider',
          //   name: '折扣设置',
          //   icon: 'Management',
          //   index: '/home/zhekou',
          //   active: true,
          //   children: []
          // },
          {
            type: 'slider',
            name: '理由设置',
            icon: 'Management',
            index: '/home/reason',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '地址黑名单',
            icon: 'Management',
            index: '/home/addressKey',
            active: true,
            children: []
          },
          {
            type: 'slider',
            name: '城市快递优先级',
            icon: 'Management',
            index: '/home/cityAddress',
            active: true,
            children: []
          }
        ]
      },
      {
        type: 'slider',
        name: '统计',
        icon: 'Management',
        index: 'tongji',
        active: true,
        children: [
          {
            type: 'slider',
            name: '仓库金额统计',
            icon: 'Management',
            index: '/home/tjcangku',
            active: true,
            children: []
          }
        ]
      }
    ],
    tabs: [],
    expandFold: false
  }),

  actions: {
    async expandFoldAct(data) {
      this.expandFold = !this.expandFold
    },
    async changeTabs(data) {
      let tabs = JSON.parse(JSON.stringify(this.tabs))

      let findTas = tabs.filter((v) => v.name == data.name && v.index == data.index)

      // 是否已存在
      if (findTas.length) {
        tabs.forEach((v, i, arr) => {
          if (v.name == data.name && v.index == data.index) {
            v.active = true
          } else {
            v.active = false
          }
        })
      } else {
        // 不能超过10个
        if (tabs.length > 10) {
          tabs = tabs.slice(1)
        }

        // 所有置为未选中
        tabs = tabs.map((v) => {
          return {
            ...v,
            active: false
          }
        })

        // 当前的激活菜单
        tabs.push({
          type: 'slider',
          name: data.name,
          icon: 'Document',
          index: data.index,
          active: true,
          children: []
        })
      }

      this.tabs = tabs
    },
    async setTabs(data) {
      this.tabs = data
    }
  }
})
